<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>登录</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/heard.css"/>
    <link rel="stylesheet" type="text/css" href="../css/login.css"/>
    <link rel="stylesheet" type="text/css" href="../css/vm.extend.css"/>
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jq.min.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
</head>


<body class="old_man_worries">
<!--顶部标题栏-->
<div class="header" id="topbar">
    <div class="left" tapmode onclick="goback()">
        <img src="../image/fhui.png" alt="" class="logoleft">
    </div>
    <div class="t">
        <span class="title">注册</span>
    </div>
</div>


<article>
    <aside>
        <div>用户名</div>
        <input type="text" id="userName" value="" placeholder="请填写登录用户名"/>
    </aside>
    <aside>
        <div>密码</div>
        <input type="password" id="pass" value="" placeholder="请填写登录密码"/>
    </aside>
    <aside>
        <div>真实名字</div>
        <input type="text" id="name" value="" placeholder="请填写真实名字"/>
    </aside>
    <aside>
        <div>电话</div>
        <input type="number" id="Tel" maxlength="11" value="" placeholder="请填写电话"/>
    </aside>
    <aside>
        <div>地址</div>
        <input type="text" id="address" value="" placeholder="请填写地址"/>
    </aside>
</article>
<footer class="vm-flex-c">
    <div class="vm-btn" onclick="submitData()">提交</div>
</footer>
</body>
<script type="text/javascript">
    var deviceId = "";
    apiready = function () {
        deviceId = api.deviceId;//设备编码
    };

    function goback() {
        api.closeFrame({name: 'zhuce'});
    }

    //登录
    function submitData() {
        var usrname = $("#userName").val();
        if (!usrname) {
            api.toast({
                msg: '用户名不能为空',
                duration: 2000,
                location: 'bottom'
            });
            return;
        }
        var reg = /^[0-9a-zA-Z]+$/;
        if (!reg.test(usrname)) {
            api.toast({
                msg: '用户名只能为字母或数字',
                duration: 2000,
                location: 'bottom'
            });
            return;
        }

        var password = $("#pass").val();
        if (!password) {
            api.toast({
                msg: '密码不能为空',
                duration: 2000,
                location: 'bottom'
            });
            return;
        }
        if (!reg.test(password)) {
            api.toast({
                msg: '密码只能为字母或数字',
                duration: 2000,
                location: 'bottom'
            });
            return;
        }

        var name = $("#name").val();
        if (!name) {
            api.toast({
                msg: '真实名字不能为空',
                duration: 2000,
                location: 'bottom'
            });
            return;
        }
        var Tel = $("#Tel").val();
        if (!Tel) {
            api.toast({
                msg: '电话号码不能为空',
                duration: 2000,
                location: 'bottom'
            });
            return;
        }
        if (!(/^1[34578]\d{9}$/.test(Tel))) {
            api.toast({
                msg: '电话号码格式有误',
                duration: 2000,
                location: 'bottom'
            });
            return false;
        }
        var address = $("#address").val();
        if (!address) {
            api.toast({
                msg: '地址不能为空',
                duration: 2000,
                location: 'bottom'
            });
            return;
        }

        api.showProgress({});
        $.ajax({
            type: "POST",
            url: "http://www.solearn.top/paotui/public/index.php/index/index/zhuce",
            dataType: "json",
            data: {usrname: usrname, password: password, name: name, Tel: Tel, address: address, deviceId: deviceId},
            success: function (res) {
                api.hideProgress();//关闭加载动画
                if (res.status == 1) {
                    //要减掉头部与尾部，默认加载主页
                    var headerH = 0;
                    var footerH = 60;
                    var frameH = api.winHeight - headerH - footerH;
                    api.openFrame({
                        name: 'login',
                        url: '../html/login.html',
                        bounces: true,  //上下滑动
                        scrollEnabled: true,
                        pageParam: {
                            usrname: usrname,
                            password: password
                        },
                        rect: {
                            x: 0,
                            y: headerH,
                            w: 'auto',
                            h: frameH
                        }
                    });
                } else {
                    api.toast({
                        msg: res.msg,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }
        });


    }

</script>
</html>
